#include <am.h>
#include <klib-macros.h>
//#include <stdio.h>
#include <uart.h>
/*
void putch(char ch);
void uart_set_baud(int baud,int system_frequency);
void uart_tr_init(void);

int main(){
  uart_set_baud(115200,50000000);
  uart_tr_init();
  putstr("FLASH-TO-MEM TEST...\n");
  asm("jr %0" : : "r"(0x80000000));
}

#define UART_REG_TR *((volatile uint32_t *)0x10000000) //发送
#define UART_REG_IE *((volatile uint32_t *)0x10000004) //中断使能
#define UART_REG_FC *((volatile uint32_t *)0x10000008) //FIFO 控制
#define UART_REG_LC *((volatile uint32_t *)0x1000000C) //线路控制
#define UART_REG_MC *((volatile uint32_t *)0x10000010) //调制解调控制
#define UART_REG_LS *((volatile uint32_t *)0x10000014) //线路状态
#define UART_REG_SR *((volatile uint32_t *)0x1000001C)
*/

void putch(char ch) {
  UART_REG_TR = ch;
  // asm  volatile("mv a0, %0; .word 0x0005006b" : :"r"(ch));
}

void uart_set_baud(int baud,int system_frequency){
  int value= system_frequency/(16*baud);
  UART_REG_LC = 0x83;
  UART_REG_TR = value;
  // asm  volatile("mv a0, %0; .word 0x0005006b" : :"r"(value));
}

void uart_tr_init(void){
UART_REG_LC = 0x03;
}



// int register eax asm("eax") = 0x80000000; // addr is a memory address
// asm("jr *%eax");
// asm volatile("jr a5, %0" : : "r" (0x80000000));
// asm volatile("jr a0, a5" : :"r"(0x80000000));